// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "SQLKeep.h"
#include "../visitor/SQLASTVisitor.h"
#include "SQLOrderBy.h"

SQLKeep_DenseRank_ptr SQLKeep_DenseRank::FIRST = SQLKeep_DenseRank_ptr(new SQLKeep_DenseRank(1 << 0, make_string_ptr("FIRST")));
SQLKeep_DenseRank_ptr SQLKeep_DenseRank::LAST = SQLKeep_DenseRank_ptr(new SQLKeep_DenseRank(1 << 1, make_string_ptr("LAST")));

SQLKeep_DenseRank::SQLKeep_DenseRank(uint64_t mask, string_ptr name)
{
  this->mask_ = mask;
  this->name_ = name;
}

// @Override
void SQLKeep::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLKeep)))
  {
    acceptChild(visitor, this->orderBy);
  }
  visitor->endVisit(SharedObject(SQLKeep));
}

SQLKeep_DenseRank_ptr SQLKeep::getDenseRank()
{
  return denseRank;
}

void SQLKeep::setDenseRank(SQLKeep_DenseRank_ptr denseRank)
{
  this->denseRank = denseRank;
}

SQLOrderBy_ptr SQLKeep::getOrderBy()
{
  return orderBy;
}

void SQLKeep::setOrderBy(SQLOrderBy_ptr orderBy)
{
  if (orderBy != nullptr)
  {
    orderBy->setParent(SharedObject(SQLKeep));
  }
  this->orderBy = orderBy;
}

SQLObject_ptr SQLKeep::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLKeep>(new SQLKeep());
  std::shared_ptr<SQLKeep> x = std::dynamic_pointer_cast<SQLKeep>(clone_tmp);
  // SQLKeep x = new SQLKeep();

  x->denseRank = denseRank;

  if (orderBy != nullptr)
  {
    x->setOrderBy(std::dynamic_pointer_cast<SQLOrderBy>(orderBy->clone()));
  }

  return x;
}
